/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evangelion.core.daoImpl;

import com.evangelion.core.bean.Seccione;
import com.evangelion.core.bean.Vehiculo;
import com.evangelion.core.dao.VehiculoDao;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * @author Usuario
 */
@Component
@Transactional
public class VehiculoDaoImpl extends AbstractDAO implements VehiculoDao {

    @Override
    public void save(Vehiculo vehiculo) {
        super.save(vehiculo);
    }

    @Override
    public Vehiculo findObjByParam(String parametro, String valor) {
        return (Vehiculo) findObjByParam(Vehiculo.class, parametro, valor);
    }

    @Override
    public List<Vehiculo> findListByParam(String parametro, String valor) {
        return findListByParam(Vehiculo.class, parametro, valor);
    }

    public List<Vehiculo> findListByParamSeccion(Seccione seccion, String parametro, String valor) {
        if (null == valor) {
            valor = "";
        }
        Query q = em.createQuery("SELECT x FROM Vehiculo x where x.seccion=:seccion and x." + parametro + " like :valor");
        q.setParameter("valor", "%" + ((null == valor) ? "" : valor) + "%");
        q.setParameter("seccion", seccion);
        return q.getResultList();
    }
}